package Controller;

import Pojo.Admin;
import Pojo.Order;
import Service.impl.AdminServiceImpl;
import Service.impl.UserServiceImpl;
import com.alibaba.fastjson.JSON;
import com.sun.istack.internal.NotNull;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

public class AdminLoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        try {
            String admin_name = request.getParameter("admin_name");
            String admin_pwd = request.getParameter("admin_pwd");
            AdminServiceImpl adminService=new AdminServiceImpl();
            Admin admin=adminService.AdminLogin(admin_name,admin_pwd);
            String s="";
            if(admin==null){
                s="fail";
            }else {
                s="success";
            }
            HashMap<Object,Object> map=new HashMap<>();
            map.put("admin",admin);
            map.put("LoginResult",s);
            response.getWriter().print(JSON.toJSONString(map));
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
